/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.ControlLayer;

/**
 *
 * @author meydlo
 */
import java.util.ArrayList;
import javaapplication6.DomainLayer.WorkerRecords;
import javaapplication6.DomainLayer.Worker;
public class WorkerControl {

    private WorkerRecords workerRecords=WorkerRecords.getWorkerRecords();
    private long id=3;

    //
    public void createWorker(String name, String phoneNo, String address,double salary,int type,String password)
    {

        id=id+1;
        workerRecords.createWorker( name, phoneNo, address, salary, type, password, id);
    }


    //
    public void deleteWorker(long id)
    {
        workerRecords.deleteWorker(id);
    }

    //
    public Worker findWorker(long id)
    {
        return workerRecords.workerByID(id);
    }

    //
    public void printWorkerInfo(long id)
    {
        try{
        workerRecords.workerByID(id).printWorkerInfo();
        }
        catch(Exception e){
            workerRecords.workerByID(id);
        }
    }

    public void printWorkerList()
    {
        workerRecords.printWorkerList();
    }
    
    public ArrayList<Worker> getWorkerList()
    {
        ArrayList<Worker> workers=workerRecords.getWorkerList();
        return workers;
    }

    //setting discount to each worker of the "Type" type
    public void setDiscountToWorkers(int type, double discount)
    {
        ArrayList<Worker> workers=getWorkerList();

        for(Worker worker : workers){

            //actual worker to comparare if fit for setting discount
            int wType=worker.getType();

            if(wType==type){
                worker.setDiscount(discount);
            }
        }
    }

}
